%{
#include <iostream>
#include <cstring>
using namespace std;

char* text=new char(255);
int istext;
FILE* outputfile;

void a(char* t, int type);

%}

digital  [0-9]+
token    TOKEN_([A-Z]|_)+

%%
{digital} {a(yytext,2);}
{token}   {a(yytext,1);}
\n        {istext=0;}
%%

void a(char* t, int type) {
	if (type==1) {
		text=new char(255);
		strcpy(text,t);
		istext=1;
	}
	else {
		if (istext) {
			char* res=new char(255);
			sprintf(res,"refect[%s]=%s",t,text);
			fprintf(outputfile,"%s\n",res);
//			printf("refect[%s]=%s\n",t,text);
			istext=0;
		}
	}
}

int main() {
	istext=0;
	outputfile=fopen("res.txt","w");
	yyin=fopen("tinyc.y","r");
//	yyout=fopen("tmp.txt","w");
	yylex();
	return 0;
}
